package com.poizon.infrastructure.center.config.starter.apollo;

import com.ctrip.framework.apollo.ConfigChangeListener;
import com.poizon.infrastructure.center.config.core.event.listener.AbstractChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;

/**
 * apollo依赖存在则自动加载
 */
@Slf4j
@ConditionalOnClass(value = {ConfigChangeListener.class, com.ctrip.framework.apollo.ConfigService.class})
public class ApolloAutoConfig {
    @Bean
    public ApolloChangeListener apolloChangeListener(AbstractChangeListener abstractChangeListener) {
        log.info(">初始化apollo配置监听器");
        return new ApolloChangeListener(abstractChangeListener);
    }

    @Bean
    public ApolloChangeListenerRegister apolloChangeListenerRegister(ApolloChangeListener apolloChangeListener) {
        log.info(">初始化apollo配置监听器注册器");
        return new ApolloChangeListenerRegister(apolloChangeListener);
    }
}
